
#include <Inklude/CThread.h>
#include <windows.h>

using namespace Inklude;

CThread::CThread()
{
	m_hThread = NULL;
}

static DWORD WINAPI __inklude_thread_func_Please_avoid_this_function_name_sadflmasdlkfa(LPVOID pCThread)
{
	return reinterpret_cast<CThread*>(pCThread)->Run();
}

bool CThread::Start()
{
    m_bRunning = true;
	m_hThread = CreateThread(NULL,
							 0,
							 __inklude_thread_func_Please_avoid_this_function_name_sadflmasdlkfa,
							 reinterpret_cast<LPVOID>(this),
							 0,
							 &m_threadId);

	return (NULL != m_hThread);
}

bool CThread::Stop()
{
	bool _bResult = false;
	if (NULL != m_hThread)
	{
        TerminateThread(m_hThread, 0);
		_bResult = (TRUE == CloseHandle(m_hThread));
		m_hThread = NULL;
        m_bRunning = false;
	}
	return _bResult;
}

bool CThread::IsRunning()
{
    return m_bRunning;
}